<?php
namespace app\api\controller;

use app\api\controller\Authbase;
use app\api\model\AlbumModel;
use app\api\model\WechatUserModel;
use think\Controller;

/**
 * 用户中心接口
 */
class UserCenter extends Authbase
{
    /**
     *
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function index() {
        $data = AlbumModel::getAlbumsByOpenId( $this->Auth_Wxuser_OpenId);
        return json(['code' => 1, 'msg' => 'success', 'data' => $data]);
    }

    /**
     * 发表
     * @return \think\response\Json
     */
    public function publish() {
        $album_id = input('album_id/d', '');
        $albumM = new AlbumModel();
        $album = $albumM->save(['is_show' => AlbumModel::IS_SHOW_YES, 'is_verify' => AlbumModel::IS_VERIFY_YES], ['id' => $album_id]);

        if ($album === false) {
            return json(['code' => 0, 'error' => '发表失败']);
        }
        return json(['code' => 1, 'msg' => 'success']);
    }
}